<style>
    /* .editorBox{
        height: 300px;
    }  */
    .layuimini-main {
        min-height: 675px;
    }
</style>

<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend style="font-size:medium;">编辑动态新闻</legend>
        </fieldset>
        <form class="layui-form" action="" style="text-align:center">
            <input type="text" name="id"  style="display: none;">
            <input type="text" name="entryPerson" style="display: none;">

            <!-- <div class="layui-form-item"> -->
            <div class="layui-input-inline">    
                <label class="layui-form-label">标题<label style="color: red;"> *</label>:</label>
                <div class="layui-input-block">
                    <input type="text" name="addDy_title" style="width:890px" id="addDy_title" lay-verify="required"
                        lay-reqtext="标题不能为空" placeholder="请输入标题" class="layui-input" spellcheck="false">
                </div>
            </div>
            <br><br>

            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <label class="layui-form-label">来源<label style="color: red;"> *</label>:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="addDy_source" style="width:400px" id="addDy_source"
                            lay-verify="required" lay-reqtext="来源不能为空" placeholder="请输入来源" class="layui-input"
                            spellcheck="false">
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">发布日期:</label>
                    <div class="layui-input-inline" style="width: 375px;">
                        <input type="text" name="addDy_sendTime" id="addDy_sendTime" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
            </div>
            <br> <br>
            <div class="layui-inline">
                <div class="editorBox" id='editorId1' name="text" style="width: 1000px;min-height:330px;"></div>
            </div>

            <div class="layui-form-item btn">           
                    <button class="layui-btn" id="dyUpdateSubmit"  lay-submit lay-filter="dyUpdate"
                    style="position:absolute;right:18%;bottom:30px;border:none;outline:none;width: 90px;height:32px;line-height:32px;
                    background-color: #FFB800;font-size: 14px;color: #ffffff;">修改</button>
                    <button class="layui-btn" onclick="closeEditDynamic();" type="button"
                    style="position:absolute;right:8%;bottom:30px;border:none;outline:none;width: 90px;height:32px;line-height:32px;
                    background-color: #cccccc;font-size: 14px;color: #ffffff;">关闭</button>    
        
            </div>
        </form>
    </div>
</div>
<style>
    .btn{
        margin-top: 50px;
        margin-bottom:50px;
    }
</style>
<!-- 富文本 -->
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.config.js"></script>
<!-- <script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.all.min.js"></script> -->
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('editorId1', {
            autoHeightEnabled: true,
            autoFloatEnabled: true,
            enableAutoSave: false,
            allowDivTransToP: false,//阻止div标签自动转换为p标签
            toolbars: [[
                'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'insertimage', 'emotion', 'attachment', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
                'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                'preview', 'searchreplace', 'drafts', 'help'
            ]]
        });

    ue.ready(function () {
            //富文本跨域解决
            if(typeof(UE_Config_Json_LKJHGFDSA)!="undefined"){
                UE.utils.extend(ue.options, UE_Config_Json_LKJHGFDSA);
            }
        });
</script>
<script>
    $(function () {
        var parent_json = parent.editData;
      
        $("input[name ='id']").val(parent_json.id)
        $("input[name ='entryPerson']").val(parent_json.entryPerson)   
        $("input[id ='addDy_title']").val(parent_json.title)
        $("input[id ='addDy_source']").val(parent_json.source)
        $("input[id ='addDy_sendTime']").val(parent_json.sendTime);
        ue.ready(function() {
          ue.setContent(parent_json.text);
        });

    });
    

    //form表单
    layui.form.render();


     //渲染日期插件
    //日期
    laydate.render({
            elem: '#addDy_sendTime',
            type: 'date',
            range: false,
            trigger: 'click',
            // theme: '#393D49',
            min: '1900-1-1'//指定日期

         });
    

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        /**
         *   初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(dyUpdate)', function (data) {   
            // var str = encodeURIComponent(ue.getContent()); //获取富文本 内容
            // text = decodeURIComponent(str); //将编码的内容解码
            text = ue.getContent();
            id = $("input[name='id']").val(),
            entryPerson=$("input[name='entryPerson']").val(),
            title = $("#addDy_title").val();
            source = $("#addDy_source").val();
            sendTime = $("#addDy_sendTime").val();
            shared.ajaxPost('/admin/dynamicNews/updateDynamicNews', {
                    id:id,
                    entryPerson:entryPerson,
                    title: title,
                    source: source,
                    sendTime: sendTime,
                    text: text,
                },function (res) {
                    if(res == "编辑成功!"){
                    $('#dyUpdateSubmit').attr('disabled', true); //提交按钮失效
                    }    
                    layer.close(parentIndex);                    
                    parent.dyRefreshTable();
                
                },{async : false})
               
                return false;
    });

    });

    /** 设置关闭按钮的click事件处理 */
    function closeEditDynamic() {
        layer.confirm('确定丢弃编辑页面内容？', function (index) {
                layer.closeAll();
            });
    }

    function getImage(thisImg,path, parameter) {        
        thisImg.src = config.server + "/" + path + "/" + parameter;
        thisImg.onerror = null;
    }

    function getFile(path){
        var url = config.server + "/" + path + "/" + parameter;
        window.location.href = url;
     }


 


</script>